package com.example.yyy

import android.graphics.Color
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import android.view.View
import com.google.android.material.appbar.AppBarLayout
import kotlinx.android.synthetic.main.activity_collapsing_new.*
import kotlinx.android.synthetic.main.activity_neste_s_v.*
import kotlin.math.abs

class CollapsingNewActivity : AppCompatActivity(),AppBarLayout.OnOffsetChangedListener {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_collapsing_new)
        setSupportActionBar(tl_csn_toolbar)
        abr_csn_bar.addOnOffsetChangedListener(this)
    }

    override fun onOffsetChanged(p0: AppBarLayout?, p1: Int) {
        Log.d("TAG", "verticalOffset=" + p1);
        val offset = abs(p1);
        val total = p0!!.totalScrollRange;
        if (offset <= 200 / 2) {
            tl_csn_expand.visibility = View.VISIBLE
            tl_csn_collapse.visibility = View.GONE
            val scale2: Float = offset.toFloat() / (200 / 2)
            val alpha2: Int = 255 * scale2.toInt()
            abr_csn_bar.setBackgroundColor(Color.argb(alpha2,25,131,209))
        }else{
            tl_csn_expand.visibility = View.GONE
            tl_csn_collapse.visibility = View.VISIBLE
            val scale3: Float = (200-offset).toFloat() / (200 / 2)
            val alpha3: Int = 255 * scale3.toInt()
            abr_csn_bar.setBackgroundColor(Color.argb(alpha3,25,131,209))
        }
    }
}